var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		prodata: '',
		isload: 0,
		hiddenmodalremark:true,
		hiddenmodalfahuo:true,
		hiddenmodalpeisong:true,
		remarkdata:'',
		expressno:'',
		index:0,
		index2:0
	},
	_onLoad: function (option) {
		var that = this;
		$.get($.pre_url + '/am.php?s=/order/scoreshoporderdetail', { id: that.options.id }, function (res) {
			that.setData({isload: 1});
			that.setData(res);
		});

	},
	delOrder: function (e) {
		var that = this;
		var orderid = e.currentTarget.dataset.id
		$.confirm('确定要删除该订单吗?', function () {
			$.post($.pre_url + '/am.php?s=/order/delOrder', { type:'scoreshop',orderid: orderid }, function (data) {
				$.success(data.msg);
				setTimeout(function () {
					$.goback();
				}, 1000)
			}, '删除中');
		})
	},
	closeOrder: function (e) {
		var that = this;
		var orderid = e.currentTarget.dataset.id
		$.confirm('确定要关闭该订单吗?', function () {
			$.post($.pre_url + '/am.php?s=/order/closeOrder', { type:'scoreshop',orderid: orderid }, function (data) {
				$.success(data.msg);
				setTimeout(function (){
					that._onLoad();
				}, 1000)
			}, '提交中');
		})
	},
	refundnopass: function (e) {
		var that = this;
		var orderid = e.currentTarget.dataset.id
		$.confirm('确定要驳回退款申请吗?', function () {
			$.post($.pre_url + '/am.php?s=/order/refundnopass', { type:'scoreshop',orderid: orderid }, function (data) {
				$.success(data.msg);
				setTimeout(function () {
					that._onLoad();
				}, 1000)
			})
		}, '提交中');
	},
	refundpass: function (e) {
		var that = this;
		var orderid = e.currentTarget.dataset.id
		$.confirm('确定要审核通过并退款吗?', function () {
			$.post($.pre_url + '/am.php?s=/order/refundpass', { type:'scoreshop',orderid: orderid }, function (data) {
				$.success(data.msg);
				setTimeout(function () {
					that.onLoad();
				}, 1000)
			})
		}, '提交中');
	},
	ispay:function(e){
		var that = this;
		var orderid = e.currentTarget.dataset.id
		$.confirm('确定要改为已支付吗?', function () {
			$.post($.pre_url + '/am.php?s=/order/ispay', { type:'scoreshop',orderid: orderid }, function (data) {
				$.success(data.msg);
				setTimeout(function () {
					that.onLoad();
				}, 1000)
			})
		}, '提交中');
	},
	setremark:function(e){
		var that = this;
		that.setData({hiddenmodalremark:false})
	},
	cancelremark:function(e){
		var that = this;
		that.setData({hiddenmodalremark:true})
	},
	setremarkdata:function(e){
		var that = this;
		that.setData({remarkdata:e.detail.value})
	},
	setremarkconfirm:function(){
		var that = this
		$.post($.pre_url + '/am.php?s=/order/setremark', { type:'scoreshop',orderid: that.data.detail.id,content:that.data.remarkdata }, function (data) {
			$.success(data.msg);
			that.setData({hiddenmodalremark:true})
			setTimeout(function () {
				that.onLoad();
			}, 1000)
		})
	},

	fahuo:function(e){
		var that = this;
		that.setData({hiddenmodalfahuo:false})
	},
	cancelfahuo:function(e){
		var that = this;
		that.setData({hiddenmodalfahuo:true})
	},
	expresschange:function(e){
		var that = this;
		that.setData({index:e.detail.value})
	},
	setexpressno:function(e){
		var that = this;
		that.setData({expressno:e.detail.value})
	},
	confirmfahuo:function(){
		var that = this
		var express = this.data.expressdata[this.data.index]
		$.post($.pre_url + '/am.php?s=/order/sendExpress', { type:'scoreshop',orderid: that.data.detail.id,express_no:that.data.expressno,express:express}, function (data) {
			$.success(data.msg);
			that.setData({hiddenmodalfahuo:true})
			setTimeout(function () {
				that.onLoad();
			}, 1000)
		})
	},
				
	peisong:function(e){
		var that = this;
		that.setData({hiddenmodalpeisong:false});
		$.post($.pre_url + '/am.php?s=/order/getpeisonguser',{},function(res){
			var peisonguser = res.peisonguser;
			var peisonguser2 = [];
			for(var i in peisonguser){
				peisonguser2.push(peisonguser[i].realname + ' - ' + peisonguser[i].tel + '(配送中'+peisonguser[i].dan+'单)');
			}
			that.setData({peisonguser:res.peisonguser,peisonguser2:peisonguser2})
		})
	},
	cancelpeisong:function(e){
		var that = this;
		that.setData({hiddenmodalpeisong:true})
	},
	peisongchange:function(e){
		var that = this;
		that.setData({index2:e.detail.value})
	},
	confirmpeisong:function(){
		var that = this
		var psid = this.data.peisonguser[this.data.index2].id
		$.post($.pre_url + '/am.php?s=/order/peisong', { type:'scoreshop',orderid: that.data.detail.id,psid:psid}, function (data) {
			$.success(data.msg);
			that.setData({hiddenmodalpeisong:true})
			setTimeout(function () {
				that._onLoad();
			}, 1000)
		})
	}
}))